using System;
using System.Configuration;
using System.Data;
using digit.Core;



namespace SMS.ServiceManager
{
    public class StadiumManager
    {
        #region CONSTRUCTORS
        static StadiumManager()
        {
            _data = new StadiumData(Util.GetConnectionString("SMSSERVICE"));
            _error = "";
        }
        #endregion

        #region ATTRIBUTES
        private static StadiumData _data;
        private static string _error;
        #endregion

        #region PROPERTIES
        public static string ErrorMessage
        {
            get
            {
                return _error;
            }
        }

        #endregion

        #region METHODS
        public static bool Insert(string stadiumName, string buildDate, string imgPath, string firstMatch, string seatNo, int teamID, string teamOther, string address, string city, string country, string history, string note, string reporter, string createdBy, DateTime createdDate, byte status)
        {
            _error = "";
            try
            {
                object[] values = new object[16];
                values[0] = Util.ReplaceNullTo(stadiumName, DBNull.Value);
                values[1] = Util.ReplaceNullTo(buildDate, DBNull.Value);
                values[2] = Util.ReplaceNullTo(imgPath, DBNull.Value);
                values[3] = Util.ReplaceNullTo(firstMatch, DBNull.Value);
                values[4] = Util.ReplaceNullTo(seatNo, DBNull.Value);
                values[5] = teamID;
                values[6] = Util.ReplaceNullTo(teamOther, DBNull.Value);
                values[7] = Util.ReplaceNullTo(address, DBNull.Value);
                values[8] = Util.ReplaceNullTo(city, DBNull.Value);
                values[9] = Util.ReplaceNullTo(country, DBNull.Value);
                values[10] = Util.ReplaceNullTo(history, DBNull.Value);
                values[11] = Util.ReplaceNullTo(note, DBNull.Value);
                values[12] = Util.ReplaceNullTo(reporter, DBNull.Value);
                values[13] = Util.ReplaceNullTo(createdBy, DBNull.Value);
                values[14] = Util.ReplaceNullTo(createdDate, DBNull.Value);
                values[15] = Util.ReplaceNullTo(status, DBNull.Value);

                return _data.Insert(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Insert(StadiumInfo info)
        {
            _error = "";
            try
            {
                object[] values = new object[16];
                values[0] = Util.ReplaceNullTo(info.StadiumName, DBNull.Value);
                values[1] = Util.ReplaceNullTo(info.BuildDate, DBNull.Value);
                values[2] = Util.ReplaceNullTo(info.ImgPath, DBNull.Value);
                values[3] = Util.ReplaceNullTo(info.FirstMatch, DBNull.Value);
                values[4] = Util.ReplaceNullTo(info.SeatNo, DBNull.Value);
                values[5] = info.TeamID;
                values[6] = Util.ReplaceNullTo(info.TeamOther, DBNull.Value);
                values[7] = Util.ReplaceNullTo(info.Address, DBNull.Value);
                values[8] = Util.ReplaceNullTo(info.City, DBNull.Value);
                values[9] = Util.ReplaceNullTo(info.Country, DBNull.Value);
                values[10] = Util.ReplaceNullTo(info.History, DBNull.Value);
                values[11] = Util.ReplaceNullTo(info.Note, DBNull.Value);
                values[12] = Util.ReplaceNullTo(info.Reporter, DBNull.Value);
                values[13] = Util.ReplaceNullTo(info.CreatedBy, DBNull.Value);
                values[14] = Util.ReplaceNullTo(info.CreatedDate, DBNull.Value);
                values[15] = Util.ReplaceNullTo(info.Status, DBNull.Value);

                return _data.Insert(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Update(long stadiumID, string stadiumName, string buildDate, string imgPath, string firstMatch, string seatNo, int teamID, string teamOther, string address, string city, string country, string history, string note, string reporter, string createdBy, DateTime createdDate, byte status)
        {
            _error = "";
            try
            {
                object[] values = new object[17];
                values[0] = stadiumID;
                values[1] = Util.ReplaceNullTo(stadiumName, DBNull.Value);
                values[2] = Util.ReplaceNullTo(buildDate, DBNull.Value);
                values[3] = Util.ReplaceNullTo(imgPath, DBNull.Value);
                values[4] = Util.ReplaceNullTo(firstMatch, DBNull.Value);
                values[5] = Util.ReplaceNullTo(seatNo, DBNull.Value);
                values[6] = teamID;
                values[7] = Util.ReplaceNullTo(teamOther, DBNull.Value);
                values[8] = Util.ReplaceNullTo(address, DBNull.Value);
                values[9] = Util.ReplaceNullTo(city, DBNull.Value);
                values[10] = Util.ReplaceNullTo(country, DBNull.Value);
                values[11] = Util.ReplaceNullTo(history, DBNull.Value);
                values[12] = Util.ReplaceNullTo(note, DBNull.Value);
                values[13] = Util.ReplaceNullTo(reporter, DBNull.Value);
                values[14] = Util.ReplaceNullTo(createdBy, DBNull.Value);
                values[15] = Util.ReplaceNullTo(createdDate, DBNull.Value);
                values[16] = Util.ReplaceNullTo(status, DBNull.Value);

                return _data.Update(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Update(StadiumInfo info)
        {
            _error = "";
            try
            {
                object[] values = new object[17];
                values[0] = info.StadiumID;
                values[1] = Util.ReplaceNullTo(info.StadiumName, DBNull.Value);
                values[2] = Util.ReplaceNullTo(info.BuildDate, DBNull.Value);
                values[3] = Util.ReplaceNullTo(info.ImgPath, DBNull.Value);
                values[4] = Util.ReplaceNullTo(info.FirstMatch, DBNull.Value);
                values[5] = Util.ReplaceNullTo(info.SeatNo, DBNull.Value);
                values[6] = info.TeamID;
                values[7] = Util.ReplaceNullTo(info.TeamOther, DBNull.Value);
                values[8] = Util.ReplaceNullTo(info.Address, DBNull.Value);
                values[9] = Util.ReplaceNullTo(info.City, DBNull.Value);
                values[10] = Util.ReplaceNullTo(info.Country, DBNull.Value);
                values[11] = Util.ReplaceNullTo(info.History, DBNull.Value);
                values[12] = Util.ReplaceNullTo(info.Note, DBNull.Value);
                values[13] = Util.ReplaceNullTo(info.Reporter, DBNull.Value);
                values[14] = Util.ReplaceNullTo(info.CreatedBy, DBNull.Value);
                values[15] = Util.ReplaceNullTo(info.CreatedDate, DBNull.Value);
                values[16] = Util.ReplaceNullTo(info.Status, DBNull.Value);

                return _data.Update(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Delete(long stadiumID)
        {
            _error = "";
            try
            {
                object[] values = { stadiumID };
                return _data.Delete(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Delete(StadiumInfo info)
        {
            _error = "";
            try
            {
                object[] values = { info.StadiumID };
                return _data.Delete(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static StadiumInfo Select(long stadiumID)
        {
            _error = "";
            try
            {
                object[] values = { stadiumID };
                DataTable dTable = _data.Select(values);
                if (dTable.Rows.Count < 1) return null;


                StadiumInfo info = new StadiumInfo(dTable.Rows[0]);
                return info;
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return null;
            }
        }

        public static DataTable SelectAll()
        {
            _error = "";
            try
            {
                return _data.SelectAll();
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return null;
            }
        }

        public static bool UpdateStatus(int stadiumId, byte bytStatus)
        {
            _error = "";
            try
            {
                object[] values = new object[2];
                values[0] = stadiumId;
                values[1] = bytStatus;
                return _data.UpdateStatus(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static DataTable SelectAllByCup(int intCup)
        {
            _error = "";
            try
            {
                return _data.SelectAllByCup(intCup);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return null;
            }
        }

        #endregion

    }
}